using Ellwood.Manage.Business.Interface;
using Ellwood.Manage.Business.MapConfig;
using Ellwood.Manage.Business.ServiceImpl;
using Ellwood.Manage.MentApi.Utility.InitDatabaseExt;
using Ellwood.Manage.MentApi.Utility.RegisterExt;
using Ellwood.Manage.MentApi.Utility.SwaggerExt;

var builder = WebApplication.CreateBuilder(args);

// 配置跨域策略
builder.CorsDomainPolicy();

if (builder.Configuration["IsInitDatabase"] == "1")
{
    // 配置SqlSugar--初始化数据库
    // 首次启动时，会自动创建数据库
    builder.InitDatabase();
}

// 注册业务
builder.InitSqlSugar();
builder.Services.AddTransient<IUserManagerService, UserManagerServiceImpl>();

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

// 引入自定义扩展
builder.AddSwaggerExt();

// AutoMapper 映射
//当您将AutoMapper升级到v13时，它现在在基本Nuget包中包含.AddAutoMapper()扩展方法,不需要在引入AutoMapper.Extensions.Microsoft.DependencyInjection包，如果引入就会报错
builder.Services.AddAutoMapper(typeof(AutoMapperConfigs));


WebApplication app = builder.Build();

 // 配置跨域策略
 app.UseCorsDomainPolicy();

// 配置HTTP请求管道。 
if (app.Environment.IsDevelopment())
{
    app.UseKnife4UiExt();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();